package com.example.liu_test.controller;


import com.example.liu_test.config.UserLoginToken;
import com.example.liu_test.mapper.AdminMapper;
import com.example.liu_test.pojo.RespBean;
import com.example.liu_test.service.IAdminService;
import com.example.liu_test.service.impl.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 刘旺
 * @data 2021-07-05
 */
@RestController
@Api(tags = "登录模块")
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminMapper adminMapper;

    @Autowired
    private TokenService tokenService;
    @Autowired
    private IAdminService iAdminService;


    /***
     *登录功能
     */
    @ApiOperation(value = "登陆", notes = "登陆")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public RespBean login(String username, String password,HttpServletResponse response) throws Exception {
       return iAdminService.login(username,password,response);
    }


    /***
     * 注销
     * @author: lw
     * @date 2021/07/08
     */
    @UserLoginToken
    @ApiOperation(value = "获取信息", notes = "获取信息")
    @RequestMapping(value = "/logOff", method = RequestMethod.GET)
    public RespBean logOff(HttpServletResponse response, HttpServletRequest request) throws Exception {
        return iAdminService.logoff(response,request);
    }

//    /***
//     * 测试用 注解sql调取管理员
//     * @author: lw
//     * @date 2021/07/09
//     */
//
//    @ApiOperation(value = "sql", notes = "sql")
//    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
//    @ResponseBody
//    public RespBean getMessage1() {
//        return RespBean.success("success", adminMapper.queryAll());
//    }


}
